import os
from dotenv import load_dotenv

load_dotenv()  # 自动加载.env文件

REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
REDIS_PORT = int(os.getenv('REDIS_PORT', 6379))
REDIS_PASSWORD = os.getenv('REDIS_PASSWORD', None)
CACHE_TTL = int(os.getenv('CACHE_TTL', 3600))

# CACHES = {
#     "default": {  # 主缓存使用Redis
#         "BACKEND": "django_redis.cache.RedisCache",
#         "LOCATION": f"redis://{REDIS_HOST}:{REDIS_PORT}/1",
#         "OPTIONS": {
#             "CLIENT_CLASS": "django_redis.client.DefaultClient",
#             "PASSWORD": REDIS_PASSWORD,
#             "SOCKET_CONNECT_TIMEOUT": 5,  # 连接超时（秒）
#             "SOCKET_TIMEOUT": 5,  # 读写超时（秒）
#             "IGNORE_EXCEPTIONS": True,  # Redis宕机时降级处理
#         },
#         "KEY_PREFIX": "hotsearch",  # 缓存键前缀
#     },
#     "local": {  # 二级缓存使用内存
#         "BACKEND": "django.core.cache.backends.locmem.LocMemCache",
#         "TIMEOUT": CACHE_TTL,
#         "MAX_ENTRIES": 1000,
#     }
# }